package com.example.springdemo.dto.exception;

import lombok.Data;

@Data
public class Result<T> {
    private String code;
    private String msg;
    private T data;

    private Result(){};

    public static <T> Result<T> success(T data){
        Result<T> success = success("success");
        success.setData(data);
        return success;
    }
    public static <T> Result<T> success(String msg){
        Result<T> result = new Result<T>();
        result.setCode("200");
        result.setMsg(msg);
        return result;
    }
    public static <T> Result<T> fail(T data){
        Result<T> fail = fail("fail");
        fail.setData(data);
        return fail;
    }
    public static <T> Result<T> fail(String msg){
        Result<T> result = new Result<T>();
        result.setCode("500");
        result.setMsg(msg);
        return result;
    }
    public static <T> Result<T> build(String code, String msg, T data){
        Result<T> result = new Result<T>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

}
